﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [System.SerializableAttribute()]
    public class DerivedSimpleUnion2 : global::Kis.Xroad.Eu.DerivedSimpleUnion {
        
        public const string AINULTKUUPÄEV = "2001-01-01T00:00:00.0000000";
        
        public const string INTEGER7 = "7";
        
        public const string KINDELSTRING = "kindel string";
        
        public DerivedSimpleUnion2(global::Xtee.Core.Schema.XsdString value) : 
                base((System.String)value) {
            this.Pattern = @"[a-zA-Z0-9-]+";
            this.Validate();
            string annot = null;
            if (value.ToString() == "2001-01-01T00:00:00.0000000") {
                annot = "Ainult kuupäev";
            }
            if (value.ToString() == "7") {
                annot = "Integer 7";
            }
            if (value.ToString() == "kindel string") {
                annot = "Kindel string";
            }
            if (annot!=null) {
                this._annotation = annot;
            }
            else {
                throw new global::Xtee.Core.Types.XteeSimpleTypeValidationException(string.Format("Enumeration on [{0}] does not allow value : [{1}] ", this.GetType().Name,value.ToString()));;
            }
        }
        
        public DerivedSimpleUnion2(global::Xtee.Core.Schema.XsdInteger value) : 
                base((System.Decimal)value) {
            this.Pattern = @"[a-zA-Z0-9-]+";
            this.Validate();
            string annot = null;
            if (value.ToString() == "2001-01-01T00:00:00.0000000") {
                annot = "Ainult kuupäev";
            }
            if (value.ToString() == "7") {
                annot = "Integer 7";
            }
            if (value.ToString() == "kindel string") {
                annot = "Kindel string";
            }
            if (annot!=null) {
                this._annotation = annot;
            }
            else {
                throw new global::Xtee.Core.Types.XteeSimpleTypeValidationException(string.Format("Enumeration on [{0}] does not allow value : [{1}] ", this.GetType().Name,value.ToString()));;
            }
        }
        
        public DerivedSimpleUnion2(global::Kis.Xroad.Eu.SimpleType1 value) : 
                base((System.Decimal)value) {
            this.Pattern = @"[a-zA-Z0-9-]+";
            this.Validate();
            string annot = null;
            if (value.ToString() == "2001-01-01T00:00:00.0000000") {
                annot = "Ainult kuupäev";
            }
            if (value.ToString() == "7") {
                annot = "Integer 7";
            }
            if (value.ToString() == "kindel string") {
                annot = "Kindel string";
            }
            if (annot!=null) {
                this._annotation = annot;
            }
            else {
                throw new global::Xtee.Core.Types.XteeSimpleTypeValidationException(string.Format("Enumeration on [{0}] does not allow value : [{1}] ", this.GetType().Name,value.ToString()));;
            }
        }
        
        public DerivedSimpleUnion2(DateTimeType0 value) : 
                base((System.DateTime)value) {
            this.Pattern = @"[a-zA-Z0-9-]+";
            this.Validate();
            string annot = null;
            if (value.ToString() == "2001-01-01T00:00:00.0000000") {
                annot = "Ainult kuupäev";
            }
            if (value.ToString() == "7") {
                annot = "Integer 7";
            }
            if (value.ToString() == "kindel string") {
                annot = "Kindel string";
            }
            if (annot!=null) {
                this._annotation = annot;
            }
            else {
                throw new global::Xtee.Core.Types.XteeSimpleTypeValidationException(string.Format("Enumeration on [{0}] does not allow value : [{1}] ", this.GetType().Name,value.ToString()));;
            }
        }
        
        public DerivedSimpleUnion2() : 
                base(string.Empty) {
        }
        
        public DerivedSimpleUnion2(string value) : 
                base(Parse(value).Value.ToString()) {
            this.Pattern = @"[a-zA-Z0-9-]+";
            this.Validate();
            string annot = null;
            if (value.ToString() == "2001-01-01T00:00:00.0000000") {
                annot = "Ainult kuupäev";
            }
            if (value.ToString() == "7") {
                annot = "Integer 7";
            }
            if (value.ToString() == "kindel string") {
                annot = "Kindel string";
            }
            if (annot!=null) {
                this._annotation = annot;
            }
            else {
                throw new global::Xtee.Core.Types.XteeSimpleTypeValidationException(string.Format("Enumeration on [{0}] does not allow value : [{1}] ", this.GetType().Name,value.ToString()));;
            }
        }
        
        public static bool TryParse(string value, out global::Kis.Xroad.Eu.DerivedSimpleUnion2 result) {
            try {
                result = new global::Kis.Xroad.Eu.DerivedSimpleUnion2(value);
                return true;
            }
            catch (System.Exception ) {
                result = null;
                return false;
            }
        }
        
        public static global::Kis.Xroad.Eu.DerivedSimpleUnion2 Parse(string value) {
            global::Xtee.Core.Schema.XsdString _XsdString = null;
            if (global::Xtee.Core.Schema.XsdString.TryParse(value,out _XsdString)) {
                return new DerivedSimpleUnion2(_XsdString);
            }
            global::Xtee.Core.Schema.XsdInteger _XsdInteger = null;
            if (global::Xtee.Core.Schema.XsdInteger.TryParse(value,out _XsdInteger)) {
                return new DerivedSimpleUnion2(_XsdInteger);
            }
            global::Kis.Xroad.Eu.SimpleType1 _SimpleType1 = null;
            if (global::Kis.Xroad.Eu.SimpleType1.TryParse(value,out _SimpleType1)) {
                return new DerivedSimpleUnion2(_SimpleType1);
            }
            DateTimeType0 _DateTimeType0 = null;
            if (DateTimeType0.TryParse(value,out _DateTimeType0)) {
                return new DerivedSimpleUnion2(_DateTimeType0);
            }
             throw new FormatException("Cannot parse to type [global::Kis.Xroad.Eu.DerivedSimpleUnion2] from string value : [" + value + "]");;
        }
    }
}
